/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bean.questionnaire;

import org.ipti.br.tag.bean.AppBaseBean;
import org.ipti.br.tag.bo.CampaignBO;
import org.ipti.br.tag.entity.Campaign;
import java.io.Serializable;
import java.util.Calendar;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;


@ManagedBean(name="campaignB")
@ViewScoped
public class CampaignBean extends AppBaseBean implements Serializable {
    
    @Inject private CampaignBO campaignBO;
    
    private Campaign campaign;
    
    public CampaignBean(){
       
    }
    
    @PostConstruct
    public void init(){
        this.campaign = new Campaign();
        this.campaign.setInitialDate( Calendar.getInstance() );
        this.campaign.setTerminalDate( Calendar.getInstance() );
    }
    
    public void save(){
        try{
            campaignBO.create(campaign);
            addInfoMessage(":campaignForm:message", "Sucesso", "Salvo com sucesso no servidor");
            rediretToHomepage();
            }catch(Exception e){
                e.printStackTrace();
                addErrorMessage(":campaignForm:message", "Erro ao salvar os dados no servidor", "Não foi possível salvar");
            }
       
    }
    
    public void rediretToHomepage(){
        redirect("/educational/home/home.xhtml");
    }

    public CampaignBO getCampaignBO() {
        return campaignBO;
    }

    public void setCampaignBO(CampaignBO campaignBO) {
        this.campaignBO = campaignBO;
    }

    public Campaign getCampaign() {
        return campaign;
    }

    public void setCampaign(Campaign campaign) {
        this.campaign = campaign;
    }
    
}
